home *** CD-ROM | disk | FTP | other *** search
/ Programming Languages Suite / ProgramD2.iso / Borland / Borland C++ V5.02 / OWLINC.PAK / HLPMANAG.H < prev    next >
C/C++ Source or Header  |  1997-05-06  |  7KB  |  250 lines

  1. //----------------------------------------------------------------------------
  2. // ObjectWindows
  3. // Copyright (c) 1995, 1997 by Borland International, All Rights Reserved
  4. //
  5. //$Revision:   10.7  $
  6. //
  7. // Declares THelpContext and THelpFileManager.
  8. //----------------------------------------------------------------------------
  9. #if !defined(OWL_HLPMANAG_H)
  10. #define OWL_HLPMANAG_H
  11.  
  12. #if defined(BI_PLAT_WIN16)
  13. # error Help manager is defined only in Win32
  14. #else
  15.  
  16. #if !defined(OWL_WINDOW_H)
  17. # include <owl/window.h>
  18. #endif
  19.  
  20. #if !defined(CLASSLIB_DLISTIMP_H)
  21. # include <classlib/dlistimp.h>
  22. #endif
  23.  
  24. #if defined(BI_NAMESPACE)
  25. namespace OWL {
  26. #endif
  27.  
  28. class _OWLCLASS THelpContext;
  29. class _OWLCLASS TWindow;
  30.  
  31. // Generic definitions/compiler options (eg. alignment) preceeding the
  32. // definition of classes
  33. #include <services/preclass.h>
  34.  
  35. //
  36. // class THelpContext
  37. // ~~~~~ ~~~~~~~~~~~~
  38. // THelpContext is a class that maintains information about a menu item id and
  39. // a child control id with a help context id.
  40. // As particular windows get and lose focus, their context tables are removed
  41. // from a global context table.
  42. //
  43. class _OWLCLASS THelpContext {
  44.   public:
  45.     THelpContext();
  46.     THelpContext(TWindow* window, int helpId, int menuId, int controlId);
  47.     THelpContext(const THelpContext&);
  48.    ~THelpContext();
  49.  
  50.     THelpContext& operator =(const THelpContext&);
  51.     int operator ==(const THelpContext&) const;
  52.  
  53.     int GetHelpFileContextId() const;
  54.     int GetMenuContextId() const;
  55.     int GetControlContextId() const;
  56.     TWindow* GetWindow() const;
  57.     void SetWindow(TWindow* window);
  58.  
  59.   private:
  60.     int HelpFileContextId;
  61.     int MenuContextId;
  62.     int ControlContextId;
  63.     TWindow* Window;
  64. };
  65.  
  66. //
  67. // class THelpFileManager
  68. // ~~~~~ ~~~~~~~~~~~~~~~~
  69. // The global context table is used by THelpFileManager, which is designed to
  70. // be a mixin for TApplication.
  71. // THelpFileManager looks for the WM_HELP message and calls the help file
  72. // with the associated context id.
  73. //
  74. class _OWLCLASS THelpFileManager : virtual public TEventHandler {
  75.   public:
  76.     THelpFileManager(const string& helpFileName);
  77.     virtual ~THelpFileManager();
  78.  
  79.     virtual void ActivateHelp(TWindow*, int helpFileContextId);
  80.     virtual void DeactivateHelp();
  81.  
  82.     void   SetHelpFile(const string& helpFileName);
  83.     string GetHelpFile() const;
  84.  
  85.     bool GetHelpContextFromControl(THelpContext&, int controlId, HWND ctrl) const;
  86.     bool GetHelpContextFromMenu(THelpContext&, int menuId) const;
  87.  
  88.     void AddContextInfo(TWindow*, int helpId, int menuId, int controlId);
  89.     void RemoveContextInfo(TWindow*);
  90.  
  91.   protected:
  92.     void EvHelp(HELPINFO*);
  93.  
  94.   private:
  95.     typedef TDoubleListImp<THelpContext> TContextList;
  96.     typedef TDoubleListIteratorImp<THelpContext> TContextListIterator;
  97.     TContextList* ContextTable;
  98.  
  99.     string HelpFileName;
  100.  
  101.   DECLARE_RESPONSE_TABLE(THelpFileManager);
  102. };
  103.  
  104. // Generic definitions/compiler options (eg. alignment) following the
  105. // definition of classes
  106. #include <services/posclass.h>
  107.  
  108. #if defined(BI_NAMESPACE)
  109. } // namespace OWL
  110. #endif
  111.  
  112. //----------------------------------------------------------------------------
  113. // Macros to simplify usage of THelpContext
  114. //
  115.  
  116. #if defined(OWLHCFAR)
  117. # define __HCFAR __far
  118. #else
  119. # define __HCFAR
  120. #endif
  121.  
  122. #define DECLARE_HELPCONTEXT(cls)               \
  123.     static THelpContext __HCFAR __hcEntries[]
  124.  
  125. #define DEFINE_HELPCONTEXT(cls)\
  126.   THelpContext __HCFAR cls::__hcEntries[] = {
  127.  
  128. #define END_HELPCONTEXT        \
  129.     {THelpContext(0, 0, 0, 0)} \
  130.   }
  131.  
  132. #define HCENTRY_MENU(hcId, menuId)                    \
  133.   {THelpContext(0, hcId, menuId, 0)}
  134.  
  135. #define HCENTRY_CONTROL(hcId, ctlId)                  \
  136.   {THelpContext(0, hcId, 0, ctlId)}
  137.  
  138. #define HCENTRY_MENU_AND_CONTROL(hcId, menuId, ctlId) \
  139.   {THelpContext(0, hcId, menuId, ctlId)}
  140.  
  141. #define SETUP_HELPCONTEXT(appCls, cls)                                  \
  142.   {                                                                     \
  143.     appCls* app = TYPESAFE_DOWNCAST(GetApplication(), appCls);          \
  144.     if (app) {                                                          \
  145.       for (THelpContext* hc = &__hcEntries[0]; !IsLastIndirectContext(*hc); hc++) { \
  146.         app->AddContextInfo(this,                                       \
  147.                             hc->GetHelpFileContextId(),                 \
  148.                             hc->GetMenuContextId(),                     \
  149.                             hc->GetControlContextId());                 \
  150.       }                                                                 \
  151.     }                                                                   \
  152.   }
  153.  
  154. #define CLEANUP_HELPCONTEXT(appCls, cls)                          \
  155.   {                                                               \
  156.     appCls* app = TYPESAFE_DOWNCAST(GetApplication(), appCls);    \
  157.     if (app)                                                      \
  158.       app->RemoveContextInfo(this);                               \
  159.   }
  160.  
  161. const int TablePtr = -1;
  162.  
  163. //----------------------------------------------------------------------------
  164. // Inline implementations
  165. //
  166.  
  167. //
  168. // Return true if the context entry is a pointer to another table.
  169. //
  170. inline bool
  171. IsIndirectHelpContext(const THelpContext& context)
  172. {
  173.   if (context.GetMenuContextId() == TablePtr &&
  174.       context.GetHelpFileContextId() == TablePtr &&
  175.       context.GetControlContextId() == TablePtr)
  176.     return true;
  177.   return false;
  178. }
  179.  
  180. //
  181. // Return true if this entry is the last entry.
  182. //
  183. inline bool
  184. IsLastIndirectContext(const THelpContext& context)
  185. {
  186.   if (context.GetMenuContextId() == 0 &&
  187.       context.GetHelpFileContextId() == 0 &&
  188.       context.GetControlContextId() == 0)
  189.     return true;
  190.   return false;
  191. }
  192.  
  193. //
  194. // Return the name of the help file.
  195. //
  196. inline string
  197. THelpFileManager::GetHelpFile() const
  198. {
  199.   return HelpFileName;
  200. }
  201.  
  202. //
  203. // Return the help file context id for the context entry.
  204. //
  205. inline int
  206. THelpContext::GetHelpFileContextId() const
  207. {
  208.   return HelpFileContextId;
  209. }
  210.  
  211. //
  212. // Return the menu id for this context entry.
  213. //
  214. inline int
  215. THelpContext::GetMenuContextId() const
  216. {
  217.   return MenuContextId;
  218. }
  219.  
  220. //
  221. // Return the child control id for this context entry.
  222. //
  223. inline int
  224. THelpContext::GetControlContextId() const
  225. {
  226.   return ControlContextId;
  227. }
  228.  
  229. //
  230. // Return the window this entry is associated with.
  231. //
  232. inline TWindow*
  233. THelpContext::GetWindow() const
  234. {
  235.   return Window;
  236. }
  237.  
  238. //
  239. // Sets the window for this context entry.
  240. //
  241. inline void
  242. THelpContext::SetWindow(TWindow* window)
  243. {
  244.   Window = window;
  245. }
  246.  
  247. #endif  // Win32
  248.  
  249. #endif  // OWL_HLPMANAG_H
  250.